/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Holds the archive portion of the assignment.
 *
 * <p>Each assignment may have two archive portions:<ul>
 * <li>Student (all content except the faculty content),</li>
 * <li>Faculty (content under the "/solution" or "/software-tests/private" folders)</li>
 * </ul></p>
 *
 * <p>This entity holds both portions seperately.</p>
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "asgn_arch")
@NamedQueries({@NamedQuery(name = "AssignmentArchive.findAll", query = "SELECT a FROM AssignmentArchive a"),
        @NamedQuery(name = "AssignmentArchive.findByUuid", query = "SELECT a FROM AssignmentArchive a WHERE a.uuid = :uuid")})
public class AssignmentArchive implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "uuid", nullable = false)
  private int uuid;
  @Lob
  @Column(name = "stdnt_archive")
  private byte[] studentArchive;
  @Lob
  @Column(name = "instr_archive")
  private byte[] facultyArchive;
  @JoinColumns({@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable = false, insertable = false, updatable =
          false)})
  @OneToOne(optional = false)
  private AssignmentProperty assignmentProperty;
  @JoinColumn( name = "archv_typ", referencedColumnName = "archv_typ", nullable = false )
  @ManyToOne( optional = false )
  private ArchiveType archiveType;

  public AssignmentArchive() {
  }

  public AssignmentArchive(int uuid) {
    this.uuid = uuid;
  }

  public int getUuid() {
    return uuid;
  }

  public void setUuid(int uuid) {
    this.uuid = uuid;
  }

  public byte[] getStudentArchive() {
    return studentArchive;
  }

  public void setStudentArchive(byte[] studentArchive) {
    this.studentArchive = studentArchive;
  }

  public byte[] getFacultyArchive() {
    return facultyArchive;
  }

  public void setFacultyArchive(byte[] facultyArchive) {
    this.facultyArchive = facultyArchive;
  }

  public AssignmentProperty getAssignmentProperty() {
    return assignmentProperty;
  }

  public void setAssignmentProperty(AssignmentProperty assignmentProperty) {
    this.assignmentProperty = assignmentProperty;
  }

  public ArchiveType getArchiveType() {
    return archiveType;
  }

  public void setArchiveType( ArchiveType archiveType ) {
    this.archiveType = archiveType;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) uuid;
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentArchive)) {
      return false;
    }
    AssignmentArchive other = (AssignmentArchive) object;
    if (this.uuid != other.uuid) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentArchive[uuid=" + uuid +  "]";
  }

}
